package com.yugao.fintech.antelope.infra.file.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yugao.fintech.antelope.infra.file.service.MediaMaterialService;
import com.yugao.fintech.antelope.infra.module.file.model.rqrs.MediaMaterialPageReq;
import com.yugao.fintech.antelope.infra.module.file.model.rqrs.MediaMaterialResp;
import com.yugao.fintech.antelope.infra.module.file.model.rqrs.MediaMaterialSaveReq;
import com.yugao.fintech.antelope.infra.module.file.model.rqrs.MediaMaterialUpdateReq;
import com.yugao.fintech.antelope.base.ram.ActionType;
import com.yugao.fintech.antelope.base.ram.RamResource;
import com.yugao.fintech.framework.core.response.Resp;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;

import java.util.List;

/**
 * 媒体素材
 */
@Api(tags = "媒体素材")
@RestController
@RequestMapping("/material")
public class MediaMaterialController {
    @Autowired
    private MediaMaterialService mediaMaterialService;

    @ApiOperation(value = "分页素材")
    @GetMapping("/page")
    @RamResource(action = "material:info:query", name = "查询素材", type = ActionType.READ)
    public Resp<IPage<MediaMaterialResp>> pageMaterial(@Validated MediaMaterialPageReq req) {
        return Resp.ok(mediaMaterialService.pageMaterial(req));
    }

    @ApiOperation(value = "查询素材")
    @GetMapping("/list")
    @RamResource(action = "material:info:query", name = "查询素材", type = ActionType.READ)
    public Resp<List<MediaMaterialResp>> listMaterial(@RequestParam("ids") List<Long> ids) {
        return Resp.ok(mediaMaterialService.listMaterial(ids));
    }

    @ApiOperation(value = "通过id查找素材")
    @GetMapping("/get")
    @RamResource(action = "material:info:query", name = "查询素材", type = ActionType.READ)
    public Resp<MediaMaterialResp> getMaterial(@RequestParam(value = "id") Long id) {
        return Resp.ok(mediaMaterialService.getMaterial(id));
    }

    @ApiOperation(value = "保存素材")
    @PostMapping("/save")
    @RamResource(action = "material:info:save", name = "保存素材", type = ActionType.WRITE)
    public Resp<?> saveMaterial(@Validated @RequestBody MediaMaterialSaveReq req) {
        return Resp.ok(mediaMaterialService.saveMaterial(req));
    }

    @ApiOperation(value = "更新素材")
    @PostMapping("/update")
    @RamResource(action = "material:info:update", name = "更新素材", type = ActionType.WRITE)
    public Resp<?> updateMaterial(@Validated @RequestBody MediaMaterialUpdateReq req) {
        return Resp.ok(mediaMaterialService.updateMaterial(req));
    }

    @ApiOperation(value = "批量删除素材")
    @DeleteMapping("/batchDelete")
    @RamResource(action = "material:info:delete", name = "删除素材", type = ActionType.WRITE)
    public Resp<?> batchDeleteMaterial(@RequestParam(value = "ids") List<Long> ids) {
        return Resp.ok(mediaMaterialService.batchDeleteMaterial(ids));
    }

    @ApiOperation(value = "删除素材")
    @DeleteMapping("/delete")
    @RamResource(action = "material:info:delete", name = "删除素材", type = ActionType.WRITE)
    public Resp<?> deleteMaterial(@RequestParam(value = "id") Long id) {
        return Resp.ok(mediaMaterialService.deleteMaterial(id));
    }
}
